package com.zjq.authoritysystem.config.swagger;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author BetOnMe
 * @version 1.0
 * @ClassName swagger2Config
 * @description: TODO swagger2配置
 * @since 2023年09月11日 22:40:47
 */
@Configuration
@EnableSwagger2WebMvc
public class swagger2Config {

    /**
     * 标题
     */
    @Value("${swagger.title}")
    private String title;

    /**
     * 描述
     */
    @Value("${swagger.description}")
    private String description;

    /**
     * 指定服务的条款和条件的 URL
     */
    @Value("${swagger.termsOfServiceUrl}")
    private String termsOfServiceUrl;

    /**
     * 联系人
     */
    @Value("${swagger.contact.name}")
    private String name;

    /**
     * 联系链接
     */
    @Value("${swagger.contact.url}")
    private String url;

    /**
     * 邮箱
     */
    @Value("${swagger.contact.email}")
    private String email;

    /**
     * 版本号
     */
    @Value("${swagger.version}")
    private String version;


    @Bean
    public Docket userRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("用户管理")
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.zjq.authoritysystem.controller.user"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket roleRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("角色管理")
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.zjq.authoritysystem.controller.role"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket permissionRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("权限管理")
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.zjq.authoritysystem.controller.permission"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket departmentRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("部门管理器")
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.zjq.authoritysystem.controller.department"))
                .paths(PathSelectors.any())
                .build();
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .termsOfServiceUrl(termsOfServiceUrl)
                .contact(new Contact(name, url, email))
                .version(version)
                .build();
    }
}
